package com.cooge.common.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.cooge.common.model.Tprogram;
import com.cooge.common.service.UserService;

import com.cooge.common.util.ReadExcle;



@Controller
@RequestMapping("excle")
public class Tprogramexcle {


	@Autowired
	 UserService userService;
	

	
	@RequestMapping(value = "input", method = RequestMethod.GET)
	public void userlist(HttpServletRequest request,HttpServletResponse response) throws IOException{
	        //得到表格中所有的数据
	    	String path="D:/20170327超清电影.xls";
	        List<Tprogram> listExcel=ReadExcle.getAllByExcel(path);       
	        String type="";
	        if(path.contains("电影")){
	        	type="film";
	        }
	        if(path.contains("综艺")){
	        	type="arts";
	        }
	        if(path.contains("电视剧")){
	        	type="tv";
	        }
	        for (Tprogram ll : listExcel) {
	            String name=ll.getName();
	            if (userService.getT(name)==0) {
	                //不存在就添加
	            	userService.countT(ll.getName(), type, ll.getCode());
//	            	insert(ll.getName(),type,ll.getCode());
	                System.out.println(name+"添加完成！！！！！！！！！！！！");
	            }else {
//	                //存在就更新
//	                String sql="update t_program set name=?,code where id=?";
//	                String[] str=new String[]{program.getName(),program.getCode()};
//	                db.AddU(sql, str);
	            	System.out.println(name+"为重复记录不需要插入！！！！！！！！！");
	            }
	        }
	    }
	}

